package com.ylxin.servlet;

import com.ylxin.entity.Book;
import com.ylxin.service.BookService;
import com.ylxin.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Hou
 * @version V1.0
 * @Project bookpro
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/15 13:18
 */
@WebServlet(name = "UpdateServlet",urlPatterns = "/update")
public class UpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
//        获取修改的信息
        Integer bookId = Integer.parseInt(request.getParameter("bookId"));
        String name = request.getParameter("name");
        String author = request.getParameter("author");
        String description = request.getParameter("description");
        String publisher = request.getParameter("publisher");
        double price = Double.parseDouble(request.getParameter("price"));

        Book book = new Book(bookId, name, price, description, author, publisher);

        BookService bookService = new BookServiceImpl();

        bookService.updateBook(book);

        response.sendRedirect(request.getContextPath() + "/bookList");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
